package net.barbierdereuille.android.AndroBib;

import net.barbierdereuille.android.AndroBib.AndroBib.StringColumn;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class StringList extends ListActivity {
    private static final String TAG = "StringList";

	private Cursor mCursor;

    @Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "Creating StringList");
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.string_list);
		
		ContentResolver content = getContentResolver();
		
		String[] proj = { StringColumn._ID, StringColumn.NAME, StringColumn.CONTENT };
		
		mCursor = content.query(StringColumn.CONTENT_URI, proj, null, null, StringColumn.DEFAULT_SORT_ORDER);
		startManagingCursor(mCursor);
		
		Log.d(TAG, "Found " + mCursor.getCount() + " strings");

		String[] from = { StringColumn.NAME, StringColumn.CONTENT };
		int[] to = { android.R.id.text1, android.R.id.text2 };
		
    	ListAdapter keys = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item, mCursor, from, to);
    	setListAdapter(keys);
	}

}
